/**
 * 判断一组多边形顶点是否为顺时针
 * @param {Array} points 多边形顶点
 * @returns {Boolean} true:顺时针 false:逆时针
 */
function isClockwise(points) {
	let sum = 0;

	for (let i = 0; i < points.length; i++) {
		let p1 = points[i];
		let p2 = points[(i + 1) % points.length];
		sum += (p2.x - p1.x) * (p2.y + p1.y);
	}

	return sum > 0;
}

function download(url, fileName) {
	const a = document.createElement('a');

	a.href = url;
	a.download = fileName;

	document.body.appendChild(a);

	a.click();

	document.body.removeChild(a);

	URL.revokeObjectURL(url);
}

export {
	isClockwise,
	download
};